package com.psdi.element;

import com.psdi.manager.GameLoader;
import com.psdi.manager.LevelSystem;
import com.psdi.physics.Collider;
import com.psdi.physics.CollisionSystem;

import javax.swing.*;
import java.util.HashSet;
import java.util.Set;

/**
 * 道具类
 * 用于处理游戏中的道具元素
 */
public class Prop extends ElementObject implements Collider {

    public Prop(int x, int y, int width, int height, ImageIcon image) {
        super(x, y, width, height, image);
        tag=Tag.PROP;
        CollisionSystem.INSTANCE.addElement(this);
    }

    public Prop() {}

    @Override
    public Size colliderSize() {
        return this.transform.size;
    }

    @Override
    public Position colliderPosition() {
        return this.transform.position;
    }

    @Override
    public Tag colliderTag() {
        return this.tag;
    }

    @Override
    public Set<Tag> colliderFilterTag() {
        Set<Tag> tags = new HashSet<>();
        tags.add(Tag.BULLET);
        tags.add(Tag.KNIFE);
        return tags;
    }

    @Override
    public void onCollisionStay(ElementObject other) {
        if(other instanceof Player) {
            LevelSystem.getINSTANCE().EXP_Up();
            setAlive(false);
        }
    }

    public ElementObject CreateProp(Position pos) { //传入敌人死亡时的位置信息
        CollisionSystem.INSTANCE.addElement(this);
        this.image = GameLoader.PropIcon;
        this.transform = new Transform(pos,new Rotation(),new Size(35, 35));
        this.tag=Tag.PROP;
        return this;
    }

}
